function decodeUnicode(str) {
  return str.replace(/\\u([0-9A-Fa-f]{4})/g, function (match, p1) {
    return String.fromCharCode(parseInt(p1, 16))
  })
}

function parseContent(input) {
  input = decodeUnicode(input)
  const regex_object = /({.*?})(?=\s*{|$)/g
  let match

  let result = {
    chat_id: null,
    content: ''
  }
  while ((match = regex_object.exec(input)) !== null) {
    try {
      const obj = JSON.parse(match[1])
      result.chat_id = obj.chat_id
      result.content += obj.content
    } catch (error) {
      console.error('Invalid JSON object:', match[1], error)
    }
  }

  return result
}
const inputString =
  '{"chat_id": 10, "content": "\\nword_counts ="}{"chat_id": 10, "content": " {}\\n\\n#"}{"chat_id": 10, "content": "\\nword_counts ="}{"chat_id": 10, "content": " {}\\n\\n#"}'
const result = parseContent(inputString)
console.log(result)
